/*
 * Copyright (c) 2017. 深圳掌控网络有限公司. All rights reserved.
 */

package com.fenxiangle.yueding.feature.focus.presenter;

import com.fenxiangle.yueding.entity.bo.FoucsListBo;
import com.fenxiangle.yueding.entity.bo.PageBo;
import com.fenxiangle.yueding.feature.focus.contract.FocusContract;
import com.fenxiangle.yueding.feature.focus.dependencies.order.DaggerFocusPresenterComponent;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class FocusPresenter implements FocusContract.Presenter {

    FocusContract.View mView;

    @Inject

    FocusContract.Model mModel;


    public FocusPresenter(FocusContract.View mView) {
        this.mView = mView;
        DaggerFocusPresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }

    @Override
    public void getOrderList(int pageIndex, int pageSize) {
        mModel.getOrderList(new PageBo(pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<FoucsListBo>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        mView.showLoading(d);
                    }

                    @Override
                    public void onNext(List<FoucsListBo> couponBoPageData) {
                        if (couponBoPageData!=null&&couponBoPageData.size()>0){
                            mView.showOrderListSuccess(couponBoPageData);
                        }else {
                            mView.showOrderListEmpty();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.dismissLoading();
                        mView.showOrderListError(e.getMessage());
                    }

                    @Override
                    public void onComplete() {
                        mView.dismissLoading();
                    }
                });
    }



    @Override
    public void getOrderListMore(int pageIndex, int pageSize) {
        mModel.getOrderList(new PageBo(pageIndex, pageSize))
                .compose(mView.bindToLife()).subscribe(new Observer<List<FoucsListBo>>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(List<FoucsListBo> couponBoPageData) {
               mView.showOrderListMoreSuccess(couponBoPageData);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showOrderListMoreError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });
    }


}
